from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
import time
testCase = "DBshop017_添加属性组，类型"
firefox=openBrowser(urlAdmin) #调用函数打开指定网址,并且获取函数的返回值,函数返回的是浏览器的对象
DBshopLoginAdmin(firefox) #调用函数登录dbshop的后台
time.sleep(1)
DBshopEnterMenu3(firefox,"商品管理","商品属性","属性")
# 添加属性
name="天天向上"
lx="下拉"
fz="好好学习"
px="255"
firefox.find_element_by_xpath('//a[contains(.,"添加属性")]').click()
# 属性分组
firefox.find_element_by_id("attribute_group_id").click()
time.sleep(1)
firefox.find_element_by_xpath("//option[text()='%s']"%fz).click()
#属性类型
firefox.find_element_by_id("attribute_type").click()
time.sleep(1)
firefox.find_element_by_xpath("//option[text()='%s']"%lx).click()
# 属性名称
firefox.find_element_by_id("attribute_name").send_keys(name)

# 清空输入框
firefox.find_element_by_id("attribute_sort").clear()
firefox.find_element_by_id("attribute_sort").send_keys(px)

# 保存
firefox.find_element_by_xpath('//button[contains(.," 保存属性信息")]').click()

#断言
try:
    firefox.find_element_by_xpath('//td[contains(.,"%s")]'%name).is_displayed()
    writeLog("%s 测试通过" % testCase)
    getPhoto(firefox)
except:
    writeLog("%s 测试失败" % testCase)
firefox.quit()